class Solution(object):
    def eraseOverlapIntervals(self, intervals):
        """
        :type intervals: List[List[int]]
        :rtype: int
        """
        intervals.sort()
        count = 0
        last = intervals[0][1]
        for i in range(1, len(intervals)):
            if intervals[i][0] >= last:
                last = intervals[i][1]
            else:
                last = min(last, intervals[i][1])
                count += 1
        return count


data = Solution()
intervals = [[1, 2], [2, 3], [3, 4], [1, 3]]
print(data.eraseOverlapIntervals(intervals))
